package org.ms.nerver.governor.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.ms.nerver.governor.fault.Fault;
import org.ms.nerver.governor.fuse.Fuse;
import org.ms.nerver.governor.po.Foo;
import org.ms.nerver.governor.retry.Retry;
import org.ms.nerver.governor.service.FooService;

public class FooServiceImpl implements FooService {

	private int time=5;
	
	public void query(Long id) {
		System.out.println("query is "+id);
	}

	@Fault(fallbackMethod="addFT")
	@Retry(retryTimes=3,fallbackRetryTimes=5)
	@Fuse()
	public Foo add(Long id, boolean state, String name, String msg) {
		throw new RuntimeException("Failback in add");
	}
	
	public Foo addFT(Long id, boolean state, String name, String msg) {
		if(time>1){
			time--;
			throw new RuntimeException("Fillback in addFT");
		}
		return new Foo(id, state, name, msg);
	}

	public List<Foo> reads() {
		System.out.println("input reads.");
		List<Foo> list=new ArrayList<Foo>();
		list.add(new Foo(1001l, true, "foo1", "This is foo1."));
		list.add(new Foo(1002l, false, "foo2", "This is foo2."));
		list.add(new Foo(1003l, true, "foo3", "This is foo3."));
		return list;
	}


}
